/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.base;

import picounit.features.base.exception.ClassNotFound;

public class Caller {
	private final StackTraceElement stackTraceElement;

	public Caller(int stackDepthAway) {
		this(new Throwable().getStackTrace()[stackDepthAway + 1]);
	}

	public Caller(StackTraceElement stackTraceElement) {
		this.stackTraceElement = stackTraceElement;
	}
	
	public String className() {
		return stackTraceElement.getClassName();
	}
	
	public String methodName() {
		return stackTraceElement.getMethodName();
	}
	
	public int lineNumber() {
		return stackTraceElement.getLineNumber();
	}

	public Class<?> callingClass() {
		try {
			return Class.forName(className());
		}
		catch (ClassNotFoundException classNotFoundException) {
			throw new ClassNotFound(classNotFoundException);
		}
	}
}